package br.com.techfor.controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.generic.dao.impl.GenericDAOImpl;
import br.com.techfor.generic.dao.GenericDAO;
import br.com.techfor.model.Funcionario;

/**
 * Servlet implementation class ExcluirFuncionario
 */
public class ExcluirFuncionario extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ExcluirFuncionario() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		GenericDAO<Funcionario, Integer> fdao = new GenericDAOImpl<Funcionario, Integer>(
				Funcionario.class);

		Integer id = Integer.parseInt(request.getParameter("id"));

		Funcionario funcionario = fdao.getBean(id);

		funcionario.setStatus("D");

		fdao.atualizar(funcionario);

		RequestDispatcher rd = request.getRequestDispatcher("/index.jsp");
		rd.forward(request, response);
	}
}
